package com.max.eshop.parsers;

import java.util.ArrayList;
import java.util.List;

import com.max.eshop.core.Reqest;

public class ParserReqest {
	private final static String space = " ";
	private ArrayList<Reqest> reqests = new ArrayList<Reqest>();
	private String[] reqestFile;

	public ArrayList<Reqest> returnReqests(String[] reqestFile) {
		for (int i = 0; i < reqestFile.length - 1; i++) {
			if (!reqestFile[i + 1].equals(null)) {
				String temp[] = reqestFile[i + 1].split(" ");
				try {
					reqests.add(new Reqest(temp[0], Integer.parseInt(temp[1])));
				} catch (NullPointerException e) {
					System.out.println("ERROR");
				}
			}
		}
		return reqests;
	}

	public String[] reqestsToSrting(List<Reqest> reqests2) {
		reqestFile = new String[reqests2.size() + 1];
		reqestFile[0] = "nameBook countReqest";
		for (int i = 0; i <= reqests2.size() - 1; i++) {
			reqestFile[i + 1] = reqests2.get(i).getNameBook() + space
					+ reqests2.get(i).getCountReqest();
		}
		return reqestFile;
	}
}